﻿@model HQPad.Models.SectAccessModel

<div class="sidebar-container sidebar-bottom-margin">
    <h2>Sect access</h2>
    @if (Model.Records.Count() > 0)
    {
        <table>
            <tbody>
                @foreach (var item in Model.Records.OrderBy(r => r.SectName).ThenBy(r => r.Access))
                {
                    <tr>
                        <td>@Html.Raw(item.SectName)</td>
                        <td @(item.Access == "High Priest" ? "class=hih-priest" : item.Access == "Priest" ? "class=priest" : "class=lay") >
                            @Html.Raw(item.Access)
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }
    else
    {
        <p>You have no sect access.</p>
    }
</div>

@if (Model.Status.Status.Count() > 0)
{
    <div class="sidebar-container sidebar-bottom-margin">
        <h2>Sect status</h2>

        <p>Assign status from 'learn invocation' skills to sects to gain known invocations.</p>
    
        @using (Html.BeginForm("Power", "Character", FormMethod.Post, new { @name = "setStatusForm", @id = "setStatusForm" }))
        {
            <table class="school-status">
                <thead>
                    <tr>
                        <th>Sect status</th>
                        <th>Rank 1-8</th>
                        <th>Rank 9</th>
                        <th>Rank 10</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="total-label">Available</td>
                        <td class="total-status">@Html.Raw(Model.Status.Totals.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level1to8).First().Total.ToString())</td>
                        <td class="total-status">@Html.Raw(Model.Status.Totals.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level9).First().Total.ToString())</td>
                        <td class="total-status">@Html.Raw(Model.Status.Totals.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level10).First().Total.ToString())</td>
                    </tr>
                    @foreach (var item in Model.Status.GetGroupedStatusAssignments())
                    {
                        <tr>
                            <td class="access-label">@Html.Raw(item.SectName)</td>
                            
                            @foreach (var typeItem in item.Items.OrderBy(s => s.Type))
                            {
                                var fieldName = string.Format("status_{0}_{1}", item.SectSlug, Enum.GetName(typeof(HQPad.Helpers.SectStatusAssignmentType), typeItem.Type));
                                <td>
                                    @Html.TextBox(fieldName, typeItem.Status.ToString())
                                    <div>@Html.ValidationMessage(fieldName, new { @class = "error" })</div>
                                </td>
                            }
                        </tr>
                    }
                    <!--<tr>
                        <td class="total-label">Spent</td>
                        <td>@Html.Raw(Model.Status.Status.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level1to8).Sum(s => s.Status).ToString())</td>
                        <td>@Html.Raw(Model.Status.Status.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level9).Sum(s => s.Status).ToString())</td>
                        <td>@Html.Raw(Model.Status.Status.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level10).Sum(s => s.Status).ToString())</td>
                    </tr>-->
                    <tr>
                        <th>Invocations</th>
                        <th></th>
                        <th></th>
                        <th></th>
                    </tr>
                    <tr>
                        <td class="total-label">Available</td>
                        <td class="total-available">@Html.Raw(Model.Status.Status.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level1to8).Sum(s => s.InvocationsAvailable).ToString())</td>
                        <td class="total-available">@Html.Raw(Model.Status.Status.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level9).Sum(s => s.InvocationsAvailable).ToString())</td>
                        <td class="total-available">@Html.Raw(Model.Status.Status.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level10).Sum(s => s.InvocationsAvailable).ToString())</td>
                    </tr>
                    <tr>
                        <td class="total-label">Learnt</td>
                        <td class="total-spent">@Html.Raw(Model.Status.Totals.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level1to8).First().InvocationsLearnt.ToString())</td>
                        <td class="total-spent">@Html.Raw(Model.Status.Totals.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level9).First().InvocationsLearnt.ToString())</td>
                        <td class="total-spent">@Html.Raw(Model.Status.Totals.Where(s => s.Type == HQPad.Helpers.SectStatusAssignmentType.Level10).First().InvocationsLearnt.ToString())</td>
                    </tr>
                    <tr>
                        <td></td>
                        <td colspan="3" class="update-button">
                            <input type="submit" value="Update" id="setStatus" name="setStatus" />
                            <div>@Html.ValidationMessage("generalError", new { @class = "error" })</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        }
    </div>
}
